import os
import numpy as np
import cv2

def search_files(directory):
    directory = os.path.normpath(directory)
    objects = {}
    for curdir, subdirs, files in os.walk(directory):
        for file in files:
            if file.endswith('.jpg'):
                label = curdir.split(os.path.sep)[-1]
                if label not in objects:
                    objects[label] = []
                path = os.path.join(curdir, file)
                objects[label].append(path)
    return objects
train_samples = search_files('./originalImage')
print(train_samples)
k = 111
for label, filenames in train_samples.items():
    for filename in filenames:
        img = cv2.imdecode(np.fromfile(filename,dtype=np.uint8),cv2.IMREAD_COLOR)
        # 对图片进行范围缩放
        h,w = img.shape[:2]
        f = 500/max(h,w)
        # fx:x 轴伸缩比例, fy:y 轴伸缩比例
        img = cv2.resize(img, (0,0), fx=f, fy=f)
        imgName = "./processImage/000%d.jpg" % k 
        k += 1
        cv2.imwrite(imgName, img)